﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace POS
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            mnuMenu.Click += new EventHandler(mnuMenu_Click);
            mnuLogin.Click += new EventHandler(mnuLogin_Click);
            mnuChangePassword.Click += new EventHandler(mnuChangePassword_Click);
            mnuExit.Click += new EventHandler(mnuExit_Click);
            mnuLogout.Click += new EventHandler(mnuLogout_Click);
            mnuViewUser.Click += new EventHandler(mnuViewUser_Click);
            mnuViewManager.Click += new EventHandler(mnuViewManager_Click);
            this.Load += new EventHandler(frmMain_Load);
        }

        void mnuMenu_Click(object sender, EventArgs e)
        {
            frmMenu frm1 = new frmMenu(this);
            frm1.MdiParent = this;
            frm1.Show();
        }

        void mnuViewManager_Click(object sender, EventArgs e)
        {
            frmViewManager frm = new frmViewManager(this);
            frm.MdiParent = this;
            frm.Show();

        }

        void mnuLogin_Click(object sender, EventArgs e)
        {
            frmLogin frm = new frmLogin(this);
            frm.MdiParent = this;
            frm.Show();

            
        }

        void mnuChangePassword_Click(object sender, EventArgs e)
        {
            frmChangePassword frmchange = new frmChangePassword(this);
            frmchange.MdiParent = this;
            frmchange.Show();

            
        }

        void mnuExit_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Do you really want to exit ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                Application.Exit();
            }
            else
            {
                this.Show();

            }

            
        }

        void mnuLogout_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Are you sure do you want to Log-out?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == System.Windows.Forms.DialogResult.Yes)
            {

                frmLogin frm = new frmLogin(this);
                frm.MdiParent = this;
                frm.Show();
                mnuLogin.Enabled = true;
                mnuLogout.Enabled = false;
                mnuManageUser.Enabled = false;
                mnuViewUser.Enabled = false;
                
            }
            else
            {
                this.Show();

            }
        }

        void mnuViewUser_Click(object sender, EventArgs e)
        {
            frmUser frm2 = new frmUser(this);
            frm2.MdiParent = this;
            frm2.Show();
        }

        void frmMain_Load(object sender, EventArgs e)
        {
            frmLogin frm = new frmLogin(this);
            frm.MdiParent = this;
            frm.Show();
            this.Show();

            mnuLogin.Enabled = false;
            mnuManageUser.Enabled = false;
            mnuLogout.Enabled =false;
        }

        public void manipulation(string accesslevel)
        {
            switch (accesslevel)
            {
                case "admin":
                    mnuManageUser.Enabled = true;
                    mnuViewUser.Enabled = true;
                    mnuLogout.Enabled = true;
                    mnuLogin.Enabled = false;
                    mnuChangePassword.Enabled = true;
                    mnuViewManager.Enabled = true;
                    break;
                case "guest":
                    mnuManageUser.Enabled = true;
                    mnuViewUser.Enabled = false;
                    mnuLogout.Enabled = true;
                    mnuLogin.Enabled = false;
                    mnuChangePassword.Enabled = true;
                    mnuViewManager.Enabled = true;
                    break;

            }
        }

        
    }
}
